package leetcode.code0466;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution3 implements IDebug {

	public int getMaxRepetitions(String s1, int n1, String s2, int n2) {
		boolean[] hash = new boolean[28];
		for (int i = 0; i < s1.length(); i++) {
			hash[s1.charAt(i) - 'a'] = true;
		}
		for (int i = 0; i < s2.length(); i++) {
			if (!hash[s2.charAt(i) - 'a']) {
				return 0;
			}
		}
		int p = 1;
		for (int i = 0, j = 0; i < s2.length(); i++, j++) {
			char c = s2.charAt(i);
			if (j == s1.length()) {
				j = 0;
				p++;
			}
			while (s1.charAt(j) != c) {
				j++;
				if (j == s1.length()) {
					j = 0;
					p++;
				}
			}
		}
		return n1 / (p * n2);
	}

	public int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	@Override
	public void debug1() {
		HelpDebug.compare(2, this.getMaxRepetitions("acb", 4, "ab", 2));
	}

	@Override
	public void debug2() {
		HelpDebug.compare(1, this.getMaxRepetitions("abc", 1, "abc", 1));
	}

	@Override
	public void debug3() {
		HelpDebug.compare(1, this.getMaxRepetitions("a", 4, "aaa", 1));
	}

	@Override
	public void debug4() {
		HelpDebug.compare(5, this.getMaxRepetitions("bkacggdiuop", 21, "cbbagoo", 1));
	}

	public void debug5() {
		HelpDebug.compare(4, this.getMaxRepetitions("aaa", 3, "aa", 1));
	}

	public static void main(String[] args) {
		Solution3 so = new Solution3();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		so.debug5();
//		int a = 3, b = 5;
//		for (int i = 0, a = 3, b = 5; i < 20; i++) {
//			System.out.println(a + " " + b + " " + a / b);
//		}
//		Solution3 so = new Solution3();
		// TODO
	}

}
